package com.zyz.sunliky.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class LoginUtils {


    public static String URL;

    public static String TOKEN_USERID;

    @Value("${spring.yunshuurl}")
    public void setURL(String url){
        URL=url;
    }

    @Value("${sunliky.token_userid}")
    public void setToken_userid(String token_userid) {
        TOKEN_USERID = token_userid;
    }

    public static String gettoken(String userid){
        HttpRequest get = HttpUtil.createGet(URL+"/api/login/sso?code="+TOKEN_USERID+",main");
        String body = get.execute().body();
        JSONObject object = JSON.parseObject(body);
        if(object!=null&&object.getInteger("errcode")==0){
            return object.getString("access_token");
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(gettoken("10086"));
    }
}
